package com.tsd.base.service.impl;

import com.tsd.base.dao.BaseInvoiceInfoMapper;
import com.tsd.base.entity.BaseInvoiceInfo;
import com.tsd.base.entity.BaseInvoiceInfoExt;
import com.tsd.base.service.BaseInvoiceInfoService;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：BaseInvoiceInfo 服务实现层
 *
 * @author Hillpool
 * @date 2022/11/04 18:14:03
 */
@Service
public class BaseInvoiceInfoServiceImpl extends BaseServiceImpl implements BaseInvoiceInfoService {

    @Resource
    private BaseInvoiceInfoMapper baseInvoiceInfoMapper;

    @Override
    public BaseInvoiceInfo getBaseInvoiceInfoById(Long id) throws Exception {
        return baseInvoiceInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public BaseInvoiceInfoExt queryBySid(String sid) throws Exception {
        return baseInvoiceInfoMapper.selectBySid(sid);
    }

    @Override
    public void deleteBaseInvoiceInfos(List<String> list, SysUser opUser) throws Exception {
        for (String sid : list) {
            BaseInvoiceInfo old = baseInvoiceInfoMapper.selectBySid(sid);
            super.checkEmpty(old, "该记录不存在");
            super.autoInjectBaseData(old, opUser, TYPE_DELETE);
            baseInvoiceInfoMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveBaseInvoiceInfo(BaseInvoiceInfo record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            baseInvoiceInfoMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            baseInvoiceInfoMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<BaseInvoiceInfoExt> findBaseInvoiceInfos(Map<String, Object> params, PageBean page) throws Exception {
        return baseInvoiceInfoMapper.selectByPage(params, page);
    }

    @Override
    public List<BaseInvoiceInfoExt> findBaseInvoiceInfos(Map<String, Object> params) throws Exception {
        return baseInvoiceInfoMapper.selectByParams(params);
    }

    @Override
    public BaseInvoiceInfoExt queryByOwnerSid(String owner_sid, int dr) throws Exception {
        return baseInvoiceInfoMapper.queryByOwnerSid(owner_sid, dr);
    }
}